package com.gnerv.battle.boot.framework.core.model;

import lombok.Getter;

/**
 * <p>
 * 通用返回状态码
 * </p>
 *
 * @author Gnerv LiGen
 */
@Getter
public enum RestResultCode {

    /**
     * 请求成功
     */
    CODE_200(200, "请求成功"),

    CODE_400(400, "业务异常"),
    CODE_401(401, "权限异常"),
    CODE_402(402, "未登陆或者登陆失效"),
    CODE_403(403, "禁止访问"),
    CODE_404(404, "资源不存在"),
    CODE_405(405, "登录失败"),
    CODE_406(406, "参数异常"),

    CODE_500(500, "系统异常"),
    CODE_503(503, "数据库异常");

    private final Integer key;
    private final String description;

    RestResultCode(Integer key, String description) {
        this.key = key;
        this.description = description;
    }

    public static RestResultCode getType(Integer key) {
        for (RestResultCode type : values()) {
            if (type.key.equals(key)) {
                return type;
            }
        }
        return null;
    }

}
